//
//  ProductDetailDataModel.m
//  Castlery
//
//  Created by xie weizhi on 8/10/17.
//  Copyright © 2017 weizhi. All rights reserved.
//

#import "ProductDetailDataModel.h"
#import <YYKit/YYKit.h>
#import "APIClient.h"

@implementation ProductDetailDataModel

- (void)requestProductWithProductID:(NSString *)productID
                         completion:(void (^)(NSError *error, Product *product))completion {
    
    [APIClient requestProductDetailWithProductID:productID success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (completion) {
            Product *product = [Product modelWithJSON:responseObject];
            completion(nil, product);
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        if (completion) {
            completion(error, nil);
        }
    }];
}

@end
